package com.jcp.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jcp.entity.Users;
import com.jcp.service.PayService;
import com.jcp.service.RegisterService;


/**
 * 缴费的控制器
 * @author 林瀚东
 *
 */
@Controller
public class PaySystemController {
	//缴费管理的service层的依赖注入
	@Autowired
	private PayService payservice;
	//UserService的依赖注入
	@Autowired
	private  RegisterService regservice;
	
	
	@PostMapping(value="addupmoney",produces="application/json;charset=utf-8")
	public ModelAndView iphonelogin(@Param(value="phoneNumber") String phoneNumber,@Param(value="money") double money) {
		boolean x =payservice.addremainder(money, phoneNumber);
		List<Users> list = payservice.selectMoney(phoneNumber);
		ModelAndView mv = new ModelAndView("PaySystem.jsp");
		mv.addObject("list", list);
		
		return mv;
	}
	
	@PostMapping(value="tiaoalibaba1")
	public String aliyun1(HttpServletRequest request,Model model) {
		model.addAttribute("money", 20);
		request.getSession().setAttribute("addadd",20);
		Date date = new Date();
		long x=date.getTime();
		int suiji = (int) (x/((Math.random()+8)*77555));
		model.addAttribute("suiji", suiji);
		return "forward:alipayindex.jsp";
	}
	@PostMapping(value="tiaoalibaba")
	public String aliyun(HttpServletRequest request,Model model) {
		int xx = Integer.parseInt(request.getParameter("money11"));
		model.addAttribute("money", xx);
		request.getSession().setAttribute("addadd",xx);
		Date date = new Date();
		long x=date.getTime();
		int suiji = (int) (x/((Math.random()+8)*77555));
		model.addAttribute("suiji", suiji);
		return "forward:alipayindex.jsp";
	}
	
	@PostMapping(value="tiaoalibaba2")
	public String aliyun2(HttpServletRequest request,Model model) {
		model.addAttribute("money", 50);
		request.getSession().setAttribute("addadd",50);
		
		Date date = new Date();
		long x=date.getTime();
		int suiji = (int) (x/((Math.random()+8)*77555));
		model.addAttribute("suiji", suiji);
		
		return "forward:alipayindex.jsp";
	}
	@PostMapping(value="tiaoalibaba3")
	public String aliyun3(HttpServletRequest request,Model model) {
		model.addAttribute("money", 100);
		request.getSession().setAttribute("addadd",100);
		Date date = new Date();
		long x=date.getTime();
		int suiji = (int) (x/((Math.random()+8)*77555));
		model.addAttribute("suiji", suiji);
		return "forward:alipayindex.jsp";
	}
	
	@PostMapping(value="tiaoalibaba4")
	public String aliyun4(HttpServletRequest request,Model model) {
		model.addAttribute("money", 300);
		request.getSession().setAttribute("addadd",300);
		Date date = new Date();
		long x=date.getTime();
		int suiji = (int) (x/((Math.random()+8)*77555));
		model.addAttribute("suiji", suiji);
		return "forward:alipayindex.jsp";
	}
	@PostMapping(value="tiaoalibaba5")
	public String aliyun5(HttpServletRequest request,Model model) {
		model.addAttribute("money", 700);
		request.getSession().setAttribute("addadd",700);
		Date date = new Date();
		long x=date.getTime();
		int suiji = (int) (x/((Math.random()+8)*77555));
		model.addAttribute("suiji", suiji);
		return "forward:alipayindex.jsp";
	}
	
	
	
	
}
